﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class VectorExtension
{
    /// <summary>
    /// 只对Vector3的x进行乘值
    /// </summary>
    /// <param name="value">乘值</param>
    /// <returns></returns>
    public static Vector3 MultiplyOnlyVectorX(this Vector3 vector, float value)
    {
        vector.x *= value;
        return vector;
    }

   
    public static Vector3 SetOnlyVectorX(this Vector3 vector, float value)
    {
        vector.x = value;
        return vector;
    }
    public static Vector3 MultiplyOnlyVectorY(this Vector3 vector, float value)
    {
        vector.y *= value;
        return vector;
    }

    public static Vector3 MultiplyOnlyVectorZ(this Vector3 vector, float value)
    {
        vector.z *= value;
        return vector;
    }

    public static Vector3 AddOnlyVectorX(this Vector3 vector, float value)
    {
        vector.x += value;
        return vector;
    }
    public static Vector3 AddOnlyVectorY(this Vector3 vector, float value)
    {
        vector.y += value;
        return vector;
    }
    public static Vector3 AddOnlyVectorZ(this Vector3 vector, float value)
    {
        vector.z += value;
        return vector;
    }

    public static Vector2 MultiplyOnlyVectorX(this Vector2 vector, float value)
    {
        vector.x *= value;
        return vector;
    }

    public static Vector2 MultiplyOnlyVectorY(this Vector2 vector, float value)
    {
        vector.y *= value;
        return vector;
    }
    public static Vector2 AddOnlyVectorX(this Vector2 vector, float value)
    {
        vector.x += value;
        return vector;
    }

    public static Vector2 AddOnlyVectorY(this Vector2 vector, float value)
    {
        vector.y += value;
        return vector;
    }

    public static bool IsPositiveInfinity(this Vector3 vector)
    {
        return vector.x == Vector3.positiveInfinity.x && vector.y == Vector3.positiveInfinity.y && vector.z == Vector3.positiveInfinity.z;
    }
    /// <summary>
    /// 检测当前位置是否可以掉落
    /// </summary>
    /// <param name="point"></param>
    /// <returns></returns>
    public static Vector3 CheckPostion(this Vector3 point)
    {

        //if (AstarPath.active == null||AstarPath.active.GetNearest(point).node.Walkable)
        //{
        //    return point;
        //}
        //else
        //{

        //    if (AstarPath.active.GetNearest(point + Vector3.right).node.Walkable)
        //    {
        //        return point + Vector3.right;
        //    }
        //    if (AstarPath.active.GetNearest(point + Vector3.left).node.Walkable)
        //    {
        //        return point + Vector3.left;
        //    }
        //    if (AstarPath.active.GetNearest(point + Vector3.up).node.Walkable)
        //    {
        //        return point + Vector3.up;
        //    }
        //    if (AstarPath.active.GetNearest(point + Vector3.down).node.Walkable)
        //    {
        //        return point + Vector3.down;
        //    }
        //    return point;
        //}
        return Vector3.zero;
    }
}
